﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ParkingLot3
{
    public class ParkingLot
    {

        private List<Car> Cars { get; set; } = new List<Car>();
        public int Id { get; set; }

        public int Capacity => MaxCount - Cars.Count;

        public bool IsAvailable => Capacity > 0; 

        public int MaxCount { get; } 

        public ParkingLot(int maxCount = 2)
        {
            MaxCount = maxCount;
        }


        public int Park(Car car)
        {
            ArgumentNullException.ThrowIfNull(car);

            Cars.Add(car);

            return car.Number;
        }

        public Car? TakeOut(int number)
        {
            var car = Cars.FirstOrDefault(c => c.Number == number);
            if (car != null)
            {
                Cars.Remove(car);
            }
            return car;
        }
    }
}
